//
//  MYGChatShareReportCell.swift
//  MYGrow
//
//  Created by 小火科技 on 2024/3/4.
//

import UIKit
import QMUIKit

class MYGChatShareReportCell: UITableViewCell {
    
    override var isSelected: Bool {
        didSet{
            rightImageView.image = isSelected ? UIImage(named: "Mine/select_icon") : UIImage(named: "Mine/normal_cion")
        }
        
        
    }
    var model:MYGMineReportModel?{
        didSet{
            guard let model = model else {
                return
            }
            nameLabel.text = model.name
            timeLabenl.text = model.time
            //addreLabel.text = model.name
            numLabel.text = "编号：\(model.number)"
            let size:CGSize = getStringSize(font: .medium(13), viewSize: CGSize(width: CGFloat(MAXFLOAT), height: SCALEWIDTH(27)), str: self.model?.name ?? "张小飞")
            nameLabel.snp.updateConstraints { make in
                make.width.equalTo(size.width + 5)
            }
        }
        
    }
    
    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        contentView.backgroundColor = .rgba(240, 240, 240, 1)
        contentView.layer.cornerRadius = 5
        
        contentView.addSubview(bgView)
        bgView.addSubview(contentImageView)
        bgView.addSubview(rightImageView)
        bgView.addSubview(nameLabel)
        bgView.addSubview(iconImageView)
        bgView.addSubview(line)
        bgView.addSubview(timeLabenl)
        bgView.addSubview(addreLabel)
        bgView.addSubview(numLabel)
        
        bgView.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(15)
            make.bottom.top.equalToSuperview()
        }
        
        contentImageView.snp.makeConstraints { make in
            make.width.height.equalTo(31)
            make.left.equalTo(37)
            make.top.equalToSuperview().offset(20)
        }
        
        rightImageView.snp.makeConstraints { make in
            make.width.height.equalTo(15)
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-15)
        }
        nameLabel.snp.makeConstraints { make in
            make.centerX.equalTo(contentImageView)
            make.top.equalTo(contentImageView.snp.bottom).offset(6.5)
            make.width.equalTo(50)
            make.height.equalTo(19)
        }
        
        iconImageView.snp.makeConstraints { make in
            make.centerY.equalTo(nameLabel)
            make.left.equalTo(nameLabel.snp.right)
        }
        
        line.snp.makeConstraints { make in
            make.width.equalTo(0.5)
            make.top.bottom.equalToSuperview().inset(7)
            make.left.equalTo(contentImageView.snp.right).offset(35.5)
        }
        
        timeLabenl.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(15)
            make.left.equalTo(line.snp.right).offset(20.5)
            make.height.equalTo(24)
        }
        
        addreLabel.snp.makeConstraints { make in
            make.left.equalTo(timeLabenl)
            make.top.equalTo(timeLabenl.snp.bottom).offset(4)
            make.height.equalTo(16.5)
        }
        
        numLabel.snp.makeConstraints { make in
            make.left.equalTo(timeLabenl)
            make.top.equalTo(addreLabel.snp.bottom).offset(4)
            make.height.equalTo(16.5)
        }
    }
    
    private lazy var bgView:UIView = {
        let bg = UIView()
        bg.backgroundColor = .white
        
        bg.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.08).cgColor
        bg.layer.shadowOffset = CGSize(width: 0, height: 0)
        bg.layer.shadowOpacity = 1
        bg.layer.shadowRadius = 17.5
        
        bg.layer.masksToBounds = true
        bg.layer.cornerRadius = 5
        
        
        return bg
    }()
    
    // MARK: - lazy load
    private lazy var contentImageView: UIImageView = {
        let imgV = UIImageView()
        imgV.image = UIImage(named: "Mine/touxiang")
        imgV.layer.masksToBounds = true
        imgV.layer.cornerRadius = 4
        return imgV
    }()
    
    private lazy var rightImageView: UIImageView = {
        let imgV = UIImageView()
        imgV.image = UIImage(named: "Mine/normal_cion")//normal_cion
        imgV.layer.masksToBounds = true
        imgV.layer.cornerRadius = 4
        return imgV
    }()

    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(13)
        label.textColor = .rgba(44, 44, 44, 1)
        label.text = "小乔"
        return label
    }()
    
    private lazy var iconImageView: UIImageView = {
        let imgV = UIImageView()
        imgV.image = UIImage(named: "Mine/male")
        imgV.layer.masksToBounds = true
        imgV.layer.cornerRadius = 4
        return imgV
    }()
    
    private var line:UIView = {
        let l = UIView()
        l.backgroundColor = .rgba(240, 240, 240, 1)
        return l
    }()
    
    private lazy var timeLabenl: UILabel = {
        let label = UILabel()
        label.font = .medium(17)
        label.textColor = .rgba(42, 42, 42, 1)
        label.text = "2019-10-22"
        return label
    }()
    
    private lazy var addreLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(102, 102, 102, 1)
        label.text = MYGUserManager.getUser()?.doctor.address ?? "北京市"
        return label
    }()
    
    private lazy var numLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(102, 102, 102, 1)
        label.text = "1245555522222"
        return label
    }()
    
}
